package outman.weibo;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;

import android.os.Bundle;

public class WeiboParameter {

    private Bundle parameters = new Bundle();

    public void add(String key, String value) {
	parameters.putString(key, value);
    }

    public void addAll(Bundle bundle) {
	parameters.putAll(bundle);
    }

    public String toGetParam() {
	String result = "?";

	for (String key : parameters.keySet()) {
	    result += key + "=" + parameters.get(key) + "&";
	}

	return result.substring(0, result.length() - 1);
    }

    public HttpEntity toPostParam() {
	List<NameValuePair> params = new ArrayList<NameValuePair>();

	for (String key : parameters.keySet()) {
	    params.add(new BasicNameValuePair(key, parameters.getString(key)));
	}

	HttpEntity entity = null;
	try {
	    entity = new UrlEncodedFormEntity(params, "UTF-8");
	} catch (UnsupportedEncodingException e) {
	    e.printStackTrace();
	}

	return entity;
    }

}
